#!/bin/bash

# postinst script for driver-cpu-amd-zen
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amdzen.conf ] && rm -f $BASEDIR/kernel/drv/amdzen.conf
	else
	    chmod 0644 "$BASEDIR/kernel/drv/amdzen.conf"
	    chown root:sys "$BASEDIR/kernel/drv/amdzen.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/amdzen ] && rm -f $BASEDIR/kernel/drv/amd64/amdzen
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/amdzen"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/amdzen"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/amdzen_stub ] && rm -f $BASEDIR/kernel/drv/amd64/amdzen_stub
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/amdzen_stub"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/amdzen_stub"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/zen_umc ] && rm -f $BASEDIR/kernel/drv/amd64/zen_umc
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/zen_umc"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/zen_umc"
	fi
	[ "$ZONEINST" = "1" ] || (grep -c "^amdzen_stub " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -i '"pci1022,1440,p" "pci1022,1441,p" "pci1022,1442,p" "pci1022,1443,p" "pci1022,1444,p" "pci1022,1445,p" "pci1022,1446,p" "pci1022,1447,p" "pci1022,1448,p" "pci1022,1449,p" "pci1022,144a,p" "pci1022,144b,p" "pci1022,144c,p" "pci1022,144d,p" "pci1022,144e,p" "pci1022,144f,p" "pci1022,1450,p" "pci1022,1460,p" "pci1022,1461,p" "pci1022,1462,p" "pci1022,1463,p" "pci1022,1464,p" "pci1022,1465,p" "pci1022,1466,p" "pci1022,1467,p" "pci1022,1480,p" "pci1022,1490,p" "pci1022,1491,p" "pci1022,1492,p" "pci1022,1493,p" "pci1022,1494,p" "pci1022,1495,p" "pci1022,1496,p" "pci1022,1497,p" "pci1022,14a4,p" "pci1022,14ad,p" "pci1022,14ae,p" "pci1022,14af,p" "pci1022,14b0,p" "pci1022,14b1,p" "pci1022,14b2,p" "pci1022,14b3,p" "pci1022,14b4,p" "pci1022,14b5,p" "pci1022,14d8,p" "pci1022,14e0,p" "pci1022,14e1,p" "pci1022,14e2,p" "pci1022,14e3,p" "pci1022,14e4,p" "pci1022,14e5,p" "pci1022,14e6,p" "pci1022,14e7,p" "pci1022,15d0,p" "pci1022,15e8,p" "pci1022,15e9,p" "pci1022,15ea,p" "pci1022,15eb,p" "pci1022,15ec,p" "pci1022,15ed,p" "pci1022,15ee,p" "pci1022,15ef,p" "pci1022,1630,p" "pci1022,1650,p" "pci1022,1651,p" "pci1022,1652,p" "pci1022,1653,p" "pci1022,1654,p" "pci1022,1655,p" "pci1022,1656,p" "pci1022,1657,p" "pci1022,166a,p" "pci1022,166b,p" "pci1022,166c,p" "pci1022,166d,p" "pci1022,166e,p" "pci1022,166f,p" "pci1022,1670,p" "pci1022,1671,p" "pci1022,1679,p" "pci1022,167a,p" "pci1022,167b,p" "pci1022,167c,p" "pci1022,167d,p" "pci1022,167e,p" "pci1022,167f,p" "pci1022,1680,p" "pci1022,1724,p" "pci1022,1725,p" "pci1022,1726,p" "pci1022,1727,p" "pci1022,1728,p" "pci1022,1729,p" "pci1022,172a,p" "pci1022,172b,p"' amdzen_stub ) )
	[ "$ZONEINST" = "1" ] || (grep -c "^amdzen " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  amdzen ) )
	[ "$ZONEINST" = "1" ] || (grep -c "^zen_umc " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  zen_umc ) )
	
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

